package com.nes.fiber.demo;

import co.paralleluniverse.fibers.Fiber;
import co.paralleluniverse.fibers.SuspendExecution;
import co.paralleluniverse.strands.SuspendableRunnable;

import java.util.concurrent.ExecutionException;

/**
 * Created by wdq on 17-3-1.
 */
public class FiberDemo1 {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Fiber start = new Fiber<Void>((SuspendableRunnable) ()-> {
                System.out.println("外部部fiber1");
                Fiber start1 = new Fiber<Void>((SuspendableRunnable) ()-> {
                        Fiber.sleep(2000);
                        System.out.println("内部fiber");
                    }
                ).inheritThreadLocals().start();

            try {
                start1.join();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
            System.out.println("外部部fiber2");
            }
        ).inheritThreadLocals().start();

        start.join();
    }
}
